package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxOrderRecord;
import com.ruoyi.system.service.IRxOrderRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单支付记录Controller
 *
 * @author hjf
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/hmk/record")
public class RxOrderRecordController extends BaseController {
    @Autowired
    private IRxOrderRecordService rxOrderRecordService;

    /**
     * 查询订单支付记录列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxOrderRecord rxOrderRecord) {
        startPage();
        List<RxOrderRecord> list = rxOrderRecordService.selectRxOrderRecordList(rxOrderRecord);
        return getDataTable(list);
    }

    /**
     * 导出订单支付记录列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:record:export')")
    //@Log(title = "订单支付记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxOrderRecord rxOrderRecord) {
        List<RxOrderRecord> list = rxOrderRecordService.selectRxOrderRecordList(rxOrderRecord);
        ExcelUtil<RxOrderRecord> util = new ExcelUtil<RxOrderRecord>(RxOrderRecord.class);
        util.exportExcel(response, list, "订单支付记录数据");
    }

    /**
     * 获取订单支付记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxOrderRecordService.selectRxOrderRecordById(id));
    }

    /**
     * 新增订单支付记录
     */
    @PreAuthorize("@ss.hasPermi('hmk:record:add')")
    //@Log(title = "订单支付记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxOrderRecord rxOrderRecord) {
        return toAjax(rxOrderRecordService.insertRxOrderRecord(rxOrderRecord));
    }

    /**
     * 修改订单支付记录
     */
    @PreAuthorize("@ss.hasPermi('hmk:record:edit')")
    //@Log(title = "订单支付记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxOrderRecord rxOrderRecord) {
        return toAjax(rxOrderRecordService.updateRxOrderRecord(rxOrderRecord));
    }

    /**
     * 删除订单支付记录
     */
    @PreAuthorize("@ss.hasPermi('hmk:record:remove')")
    //@Log(title = "订单支付记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxOrderRecordService.deleteRxOrderRecordByIds(ids));
    }
}
